package com.lg.partition31;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/5/24 9:10
 */
public class P3047USACO12FEB_NearbyCowsG {

    private static final int N = 100010, M = 2 * N, K = 22;
    private static int[] h = new int[N], e = new int[M], ne = new int[M], hw = new int[N];
    private static long[][] f1 = new long[N][K], f2 = new long[N][K];
    private static int n, k, idx = 0;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt(); k = nextInt();
        Arrays.fill(h, -1);
        for (int i = 0; i < n - 1; i++) {
            int a = nextInt(), b = nextInt();
            add(a, b);
            add(b, a);
        }
        for (int i = 1; i <= n; i++) f2[i][0] = f1[i][0] = hw[i] = nextInt();
        dfs1(1, 0);
        for (int i = 0; i <= k; i++) f2[1][i] = f1[1][i];
        dfs2(1, 0);
        for (int i = 1; i <= n; i++) writer.println(f2[i][k]);
        writer.flush();
    }

    private static void dfs2(int u, int fa) {
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (v == fa) continue;
            f2[v][1] = f2[u][0] + f1[v][1];
            for (int j = 2; j <= k; j++) {
                f2[v][j] = f2[u][j - 1] + f1[v][j] - f1[v][j - 2];
            }
            dfs2(v, u);
        }
    }

    private static void dfs1(int u, int fa) {
        f1[u][1] = f1[u][0];
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (v == fa) continue;
            dfs1(v, u);
            f1[u][1] += f1[v][0];
            for (int j = 2; j <= k; j++) f1[u][j] += f1[v][j - 1];
        }
        for (int i = 2; i <= k; i++) f1[u][i] += f1[u][0];
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
